package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Answer;
import com.whxy02.tolearn.app.dao.AnswerDao;
import com.whxy02.tolearn.app.service.AnswerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AnswerServiceImpl implements AnswerService {
    private QueryWrapper<Answer> wrapper=new QueryWrapper<>();

    @Resource
    AnswerDao answerDao;

    @Override
    public List<Answer> getAll() throws Exception {
        return answerDao.selectList(null);
    }

    @Override
    public Answer getById(Integer id) throws Exception {
        return answerDao.selectById(id);
    }

    @Override
    public int save(Answer answer) throws Exception {
        return answerDao.insert(answer);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return answerDao.deleteById(id);
    }

    @Override
    public int change(Answer answer) throws Exception {
        return answerDao.updateById(answer);
    }

    @Override
    public Answer getByQuestionId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("question_id",id);
        return answerDao.selectOne(wrapper);
    }
}
